package com.xucia.auth.test;
import org.testng.annotations.*;



import com.xucia.jsponic.data.Persistable;
import com.xucia.jsponic.data.GlobalData;
import com.xucia.jsponic.data.Identifiable;
import com.xucia.jsponic.data.PersistableList;
import com.xucia.jsponic.data.PersistableImpl;
import com.xucia.jsponic.security.User;
public class AnonymousUser {
	User user;
	Persistable root;
	Persistable website;
	@Configuration(groups = {"data"}, beforeTest = true)
  	public void setUp() {
        user = User.getUserByTicket("-2734538135534173569","127.0.0.1"); // User.authenticate("michelle","seawater");
        user.registerThisThread();
        root = User.getRootObject();
		//website.put("testArea",new PersistentObjectHandler());
		Persistable testArea = (Persistable) website.get("testArea");
		//testArea.put(GlobalData.TEMPLATE_FIELD,new PersistentObjectHandler());
		//website.put("testArea2",new PersistentObjectHandler());
	}
	@Test(groups={"data"})
	public void retrievePageBody() {
/*		Entity content = (Entity) website.get(GlobalData.CONTENT_FIELD);
		DataObjectList pages = (DataObjectList) content.get("pages");
		Entity page = (Entity) pages.get(0);
		Object body = page.get("body");
		System.out.println("body is " + body.getClass());*/
	}
	@Test(groups={"data"})
	public void testAreaAvailable() {
		assert website.get("testArea") instanceof Persistable;
		assert website.get("testArea2") instanceof Persistable;
	}
	@Test(groups={"data"})
	public void testBasis() {
		Persistable testArea = (Persistable) website.get("testArea");
		Persistable basis = ((Persistable) testArea.get(GlobalData.BASIS_FIELD));
		//basis.put("field1","value1");
		assert "value1".equals(testArea.get("field1"));
		//basis.put("field2",new PersistentObjectHandler());
		System.err.println(((Identifiable) testArea.get("field2")).getId());
		assert testArea.get("field2") instanceof Persistable;
		assert website.get("testArea2") instanceof Persistable;
	}
	
}
